﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T.ApiResults;
using T.ApprovalRecord;
using T.Personnel.Read.API.Application.Command.ApprovalCommand;

namespace T.Personnel.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class ApprovalController : ControllerBase
    {
        private readonly IMediator mediator;

        public ApprovalController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 返回审批列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<ApprovalRecordd>>> GetApprovalRecorddsAsync([FromQuery] GetApprovalCommand command)
        {
            ApiResult<List<ApprovalRecordd>> result = new ApiResult<List<ApprovalRecordd>>();
            try
            {
                result.Data = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
                throw;
            }
        }
    }
}
